<template>
	<view class="home">
		<!-- 账号信息 -->
		<view class="header" ref='top'>
			<view class="account_info">
				<img :src="personAvatar" class="account" v-if="companyId == 0" @click="personCenter"/>
				<img :src="companyAvatar" class="account" v-else @click="comapnyCenter"/>
				<view @click="toggle">
					<view class="over_p">
						<template v-if="companyId == 0">
						<view class="com_name">{{ name }}</view>
						</template>
						<template v-else>
						<view class="com_name" v-if="companyWith >= 220" style="width: 414rpx;">{{ name }}</view>
						<view class="com_name" v-if="companyWith < 220">{{ name }}</view>
						</template>
						<!-- 实名认证图标 -->
						<personalGreen v-if="isCertify == 1 && companyId == 0" class="certiyImg" />
						<personalGray v-if="isCertify == 0 && companyId == 0" class="certiyImg" />
						<companyGreen v-if="isCertify == 1 && companyId != 0" class="certiyImg" />
						<companyGray v-if="isCertify == 0 && companyId != 0" class="certiyImg" />
						<span v-if="isCertify == 1">已认证</span>
						<span v-if="isCertify == 0">未认证</span>
						<i class="iconfont jiantou">&#xe87e;</i>
					</view>
					<view class="sign_item">合同签署量：{{remainingNum}}次</view>
				</view>
			</view>
		</view>
		<!-- 任务处理 -->
		<swiperTabHead :tabBars="companyId == 0 ?labelList:labelListCom" :tabIndex="tabIndex" @tabtap="tabtap" class="tabs"></swiperTabHead>
		<swiper :current="tabIndex" duration="800" :style="{height: boxHeight}" @change="handleSwiperChange">
			<swiper-item :key="index" v-for="(item,index) in companyId == 0 ?labelList:labelListCom">
				<!-- 待我处理 -->
				<view v-show="tabIndex === 0" class="tabplane_top">
					<scroll-view scroll-y v-if="listContractSignMine.length !== 0" :style="{height: boxHeight}" @scrolltolower="onreachBottom(listContractSignMine)">
						<view class="tabspane" v-for="(item,index) in listContractSignMine" :key="index">
							<view class="xieyi" style="position: relative;">
								<view @click="openContract(item)">
									<view class="contract_title">{{ item.contractName }}</view>
									<view class="contract_num">合同编号：{{ item.contractNumber }}</view>
								</view>
								<!-- 更多操作 -->
								<rudon-rowMenuDotDotDot :clear="false" :localdata="item.status == 1?moreOpertionSign:moreOpertionPre" @change="operMeDropdown($event,item,index)">
									<view class="iconfont outIcon">&#xe656;</view>
								</rudon-rowMenuDotDotDot>
							</view>
							<view class="content" @click="openContract(item)"> 
								<view class="contr_compeo">签约方：{{ item.signCompanyAllName }}</view>
								<view>合同发起时间：{{ item.createTime }}</view>
								<view class="flex_between">
									<view v-if="item.signExpiryDate !== null">签署截止时间：{{ item.signExpiryDate }}</view>
									<view v-else>签署截止时间：--</view>
									<span v-if="item.contractTipEndTime > 1">{{ item.contractTipEndTime }}小时后截止</span>
									<span v-if="item.contractTipEndTime <= 1">签署即将逾期</span>
								</view>
								
							</view>
							<view class="sign" @click="openContract(item)">
								<view v-if="item.signStatus==$enums.contract_sign_flow_status.ONE">拟稿阶段 >>
									<span v-if="item.status==$enums.contractStatus.ONE" class="marSat">签署信息待我设置</span>
									<span v-if="item.status==$enums.contractStatus.WAIT" class="marSat">待我签署</span>
									<span v-if="item.status==$enums.contractStatus.CONTROL_SET"
										class="marSat">合同内容待我填写</span>
									<span v-if="item.status==$enums.contractStatus.CONTENT_FILL"
										class="marSat">签章位置待我指定</span>
									<span v-if="item.status==$enums.contractStatus.STAMP" class="marSat">待我签署</span>
									<span v-if="item.status==$enums.contract_sign_flow_status.ALL_OK"
										class="marSat">签署全通过</span>
									<span v-if="item.status==$enums.contract_sign_flow_status.REJECT"
										class="marSat">拒签合同待签署</span>
								</view>
								<view v-if="item.signStatus==1">签署阶段>>
									<span v-if="item.status==$enums.contract_sign_flow_status.WAIT"
										class="marSat">待我签署</span>
								</view>
								<span v-if="item.signStatus==0">
									<span v-if="item.status==$enums.contractStatus.ONE">立即设置</span>
									<span v-if="item.status==$enums.contractStatus.WAIT">立即签署</span>
									<span v-if="item.status==$enums.contractStatus.CONTROL_SET">立即填写</span>
									<span v-if="item.status==$enums.contractStatus.CONTENT_FILL">立即指定</span>
									<span v-if="item.status==$enums.contractStatus.STAMP">立即签署</span>
									<span v-if="item.status==$enums.contract_sign_flow_status.REJECT">立即签署</span>
								</span>
								<span v-if="item.signStatus==1 && companyId != 0">
									<span v-if="item.status==$enums.contract_sign_flow_status.WAIT">立即签署</span>
								</span>
							</view>
						</view>
						<!-- 加载更多--> 
						<uni-load-more color="#00a660" :status="loadStatus"/>
					</scroll-view>
					<!-- 暂无数据 -->
					<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
				</view>
				<!-- 待我方处理 -->
				<view v-show="tabIndex === 1" class="tabplane_top" v-if="companyId !== 0" >
					<scroll-view scroll-y v-if="listContractSignOur.length !== 0" :style="{height: boxHeight}" @scrolltolower="onreachBottom(listContractSignOur)">
						<view class="tabspane" v-for="(item,index) in listContractSignOur" :key="index">
							<view class="xieyi">
								<view @click="openOtherContract(item)">
									<view class="contract_title">{{ item.contractName }}</view>
									<view class="contract_num">合同编号：{{ item.contractNumber }}</view>
								</view>
							</view>
							<view class="content" @click="openOtherContract(item)">
								<view class="contr_compeo">签约方：{{ item.signCompanyAllName }}</view>
								<view>合同发起时间：{{ item.createTime }}</view>
								<view class="flex_between">
									<view v-if="item.signExpiryDate !== null">签署截止时间：{{ item.signExpiryDate }}</view>
									<view v-else>签署截止时间：--</view>
									<span v-if="item.contractTipEndTime > 1">{{ item.contractTipEndTime }}小时后截止</span>
									<span v-if="item.contractTipEndTime <= 1">签署即将逾期</span>
								</view>
								
							</view>
							<view class="sign" style="display: flex;justify-content: space-between;">
								<p>签署阶段 >
									<text v-if="item.status==1" class="marSat">待我方签署【签署人：{{ item.sealerName }}】</text>
								</p>
								<span class="text-primary" @click="hurry(item)">催一下</span>
							</view>
						</view>
						<!-- 加载更多 -->
						<uni-load-more color="#00a660" :status="loadStatus" />
					</scroll-view>
					<!-- 暂无数据 -->
					<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
				</view>
				<!-- 待他方处理 -->
				<view v-show="companyId == 0 ?tabIndex === 1:tabIndex === 2" class="tabplane_top">
					<scroll-view scroll-y v-if="listContractSignOther.length !== 0" :style="{height: boxHeight}" @scrolltolower="onreachBottom(listContractSignOther)" >
						<view class="tabspane" v-for="(item,index) in listContractSignOther" :key="index">
							<view class="xieyi">
								<view @click="openOtherContract(item)">
									<view class="contract_title">{{ item.contractName }}</view>
									<view class="contract_num">合同编号：{{ item.contractNumber }}</view>
								</view>
							</view>
							<view class="content" @click="openOtherContract(item)">
								<view class="contr_compeo">签约方：{{ item.signCompanyAllName }}</view>
								<view>合同发起时间：{{ item.createTime }}</view>
								<view class="flex_between">
									<view v-if="item.signExpiryDate !== null">签署截止时间：{{ item.signExpiryDate }}</view>
									<view v-else>签署截止时间：--</view>
									<span v-if="item.contractTipEndTime > 1">{{ item.contractTipEndTime }}小时后截止</span>
									<span v-if="item.contractTipEndTime <= 1">签署即将逾期</span>
								</view>
							</view>
							<view class="sign" style="display: flex;justify-content: space-between;">
								<p>签署阶段 >
									<text v-if="item.status==1" class="marSat">待他方签署【签署人：{{item.allSealerName }}】</text>
								</p>
								<span class="text-primary" style="width: 140rpx;display: flex;justify-content: flex-end" @click="hurry(item)">催一下</span>
							</view>
						</view>
						<!-- 加载更多 -->
						<uni-load-more color="#00a660" :status="loadStatus"/>
					</scroll-view>
					<!-- 暂无数据 -->
					<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
				</view>
				<!-- 签署全通过 -->
				<view v-show="companyId == 0 ?tabIndex === 2:tabIndex === 3" class="tabplane_top">
					<scroll-view scroll-y v-if="listContractSignAllSuccess.length !== 0" :style="{height: boxHeight}" @scrolltolower="onreachBottom(listContractSignAllSuccess)">
						<view class="tabspane" v-for="(item,index) in listContractSignAllSuccess" :key="index">
							<view class="xieyi">
								<view @click="openContract(item)">
									<view class="contract_title">{{ item.contractName }}</view>
									<view class="contract_num">合同编号：{{ item.contractNumber }}</view>
								</view>
								<!-- 更多操作 -->
								<rudon-rowMenuDotDotDot :clear="false" :localdata="moreOpertionPass" @change="operAllPassDropdown($event,item)">
									<view class="iconfont outIcon">&#xe656;</view>
								</rudon-rowMenuDotDotDot>
							</view>
							<view class="content">
								<view class="contr_compeo" @click="openContract(item)">签约方：{{ item.signCompanyAllName }}
								</view>
								<view @click="openContract(item)">合同发起时间：{{ item.createTime }}</view>
								<view @click="openContract(item)">签署完成时间：{{ item.sealTime }}</view>
								<view>合同终止时间：
									<text v-if="item.contractEndTime==null" class="text-primary" @click.stop="settingEndTime(item)">
										<text v-if="item.isStarter == 0">立即设置</text>
										<text v-else style="color: #ff5722;">立即设置</text>
									</text>
									<text v-if="item.contractEndTime > 0">{{ item.contractEndTime }}天后合同失效</text>
									<text v-if="item.contractEndTime == 0">今天后合同失效</text>
									<text v-if="item.contractEndTime < 0">合同已失效</text>
								</view>
                <view v-if="$store.getters.staffInfo.companyId!=0">经办人：{{ item.signerName }}</view>
							</view>
							<view class="sign">
                <p>签署全通过</p>
								<span v-if="item.contractTipEndTime > 0" class="certiy">{{ item.contractTipEndTime }}天后合同失效</span>
							</view>
						</view>
						<!-- 加载更多 -->
						<uni-load-more color="#00a660" :status="loadStatus" />
					</scroll-view>
					<!-- 暂无数据 -->
					<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
				</view>
				<!-- 签署已终止 --> 
				<view scroll-y v-show="companyId == 0 ?tabIndex === 3:tabIndex === 4" class="tabplane_top">
					<scroll-view scroll-y v-if="listContractSignBack.length !== 0" :style="{height: boxHeight}" @scrolltolower="onreachBottom(listContractSignBack)">
						<view class="tabspane" v-for="(item,index) in listContractSignBack" :key="item.id">
							<view class="xieyi">
								<view @click="openOtherContract(item)">
									<view class="contract_title">{{ item.contractName }}</view>
									<view class="contract_num">合同编号：{{ item.contractNumber }}</view>
								</view>
								<!-- 更多操作 -->
								<rudon-rowMenuDotDotDot :clear="false" :localdata="moreOpertionBack" @change="operBackPassDropdown($event,item,index)">
									<view class="iconfont outIcon">&#xe656;</view>
								</rudon-rowMenuDotDotDot>
							</view>
							<view class="content" @click="openOtherContract(item)">
								<view class="contr_compeo">签约方：{{ item.signCompanyAllName }}</view>
								<view>合同发起时间：{{ item.createTime }}</view>
								<view v-if="item.status == 15">逾期未签时间：{{ item.signExpiryDate }}</view>
								<view v-if="item.status == 13">拒签终止时间：{{ item.revokeTime }}</view>
								<view v-if="item.status == 14">撤回终止时间：{{ item.revokeTime }}</view>
								<view v-if="item.status == 20">失效终止时间：{{ item.revokeTime }}</view>
								<view v-if="item.status == 22">失效终止时间：{{ item.revokeTime }}</view>
								<view class="flex_between"><view>经办人：{{ item.signerName }} </view>
								<span v-if="item.status == $enums.contract_sign_flow_status.OUT_DATE" @click.stop="outDateSetting(item)">签署延期</span>
								<span v-if="item.status == $enums.contract_sign_flow_status.REJECT" @click.stop="openContract(item)">继续签署</span>
								</view>                          
							</view>
							<view class="sign" style="display: flex;justify-content: space-between;">
								<p>签署阶段 >
									<text class="marSat">签署已终止</text>
								</p>
								<template v-for="(dictItem, index) in dicts.contract_sign_flow_status">
								  <template v-if="item.status == dictItem.value">
									<span class="errorColor">{{dictItem.text}}</span>
								  </template>
								</template>
							</view>
						</view>
						<!-- 加载更多 -->
						<uni-load-more color="#00a660" :status="loadStatus" />
					</scroll-view>
					<!-- 暂无数据 -->
					<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
				</view>
				<!-- 临期合同 -->
				<view v-show="companyId == 0 ?tabIndex === 4:tabIndex === 5" class="tabplane_top" >
					<scroll-view  scroll-y v-if="listContractArchiveslistExpiredContract.length !== 0" :style="{height: boxHeight}" @scrolltolower="onreachBottom(listContractArchiveslistExpiredContract)">
						<view class="tabspane" v-for="(item,index) in listContractArchiveslistExpiredContract"
							:key="index">
							<view class="xieyi">
								<view @click="openContract(item)">
									<view class="contract_title">{{ item.contractName }}</view>
									<view class="contract_num">合同编号：{{ item.contractNumber }}</view>
								</view>
								<!-- 更多操作 -->
								<rudon-rowMenuDotDotDot :clear="false" :localdata="moreOpertionTime" @change="operExpiredDropdown($event,item)">
									<view class="iconfont outIcon">&#xe656;</view>
								</rudon-rowMenuDotDotDot>
							</view>
							<view class="content" @click="openContract(item)">
								<view class="contr_compeo">签约方：{{ item.signCompanyAllName }}</view>
								<view>合同发起时间：{{ item.createTime }}</view>
								<view>签署完成时间：{{ item.sealTime }}</view>
								<view>合同终止时间：
									<text v-if="item.contractEndTime==null">未设置</text>
									<text v-else>{{ item.contractEndTime }}</text>
								</view>
							</view>
							<view class="sign">
								<p>临期合同（经办人：{{ item.signerName }})</p>
								<span v-if="item.contractTipEndTime > 0"
									class="certiy">{{ item.contractTipEndTime }}天后合同失效</span>
								<span v-if="item.contractTipEndTime == 0" class="certiy">今天后合同失效</span>
								<span v-if="item.contractTipEndTime < 0" class="certiy">合同已失效</span>
							</view>
						</view>
						<!-- 加载更多 -->
						<uni-load-more color="#00a660" :status="loadStatus" />
					</scroll-view>
					<!-- 暂无数据 -->
					<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
				</view>
			</swiper-item>
		</swiper>
		<identityPoup ref="popup" @changeCompany="changeCompany" />
		<!-- 撤销合同 -->
		<revoke-dialog ref="refusePopup" :id="invalidContractId" :invalid-is-starter="invalidIsStarter" />
		<!-- 法定代表人 -->
		<legal-certify ref="legalCertify"></legal-certify>
		<!-- 提醒弹窗 -->
		<remind-dialog ref="remindPupop"></remind-dialog>
		<!-- 个人未实名认证显示 -->
		<personal-real-name ref="personalAuth"></personal-real-name>
	</view>
</template>
<script>
import personalRealName from "@/components/identityPoup/personalRealName"
import remindDialog from "@/components/remindDialog/index"
import legalCertify from "./signWeb/legalCertify"
import config from '@/config'
import companyGray from "@/components/svg/companyGray"
import companyGreen from "@/components/svg/companyGreen"
import personalGray from "@/components/svg/personalGray"
import personalGreen from "@/components/svg/personalGreen"
import swiperTabHead from "@/components/slideTab/slideTab"
import revokeDialog from "@/components/revokeDialog/revokeDialog"
import identityPoup from "@/components/identityPoup/identityPoup"
import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty'
import {listContractArchiveslistExpiredContract} from "../api/contractArchives";
import {parseTime, transformTime} from "../utils/common";
import {getDateDiff, getHourNowDiff} from "../utils/ruoyi";
import {
  listContractSignAllSuccess,
  listContractSignBack,
  listContractSignOther,
  listContractSignOur,
  listMainPageMe
} from "@/api/ec/work/contract/contractSign";
import {updateSession} from "../api/userInfo";
import {changeUser} from "../api/login";
import {getRemainingNum} from "../api/staff";
import {againNewContract, contractHurry, delContract,getContractSignDetail} from "@/api/ec/work/contract/contract";
import {getStaffCertification} from "@/api/ec/person/certification/info";
import {getLegalChangeRecordAuthAdmin} from "../api/ec/console/index";
import {deleteIndexTask} from "../api/ec/work/contract/contractSign";
import {getDictsByNameForUni} from "@/utils/dicts";
export default {
		components: {
			revokeDialog,
			companyGray,
			personalGray,
			personalGreen,
			companyGreen,
			luanqingEmpty,
			swiperTabHead,
			identityPoup,
			legalCertify,
			remindDialog,personalRealName
		},
		data() {
			return {
				dicts:{
					contract_sign_flow_status:[]
				},
				companyWith:null, //企业名字长度 
				boxHeight: '', //swiper滚动区域高度
				total: 0, //总条数
				loadStatus: 'loading', //是否加载中 //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				host: config.baseUrl,
				invalidIsStarter: false, // 撤回类型 是否是发起方撤回
				systemStaffId: this.$store.getters.staffId,
				itemTop:0,
				invalidContractId: 0, // 撤销作废合同id
				isCertify: '',
				remainingNum: 0, // 剩余签署次数
				companyId: this.$store.getters.staffInfo.companyId, // 0个人
				personAvatar: require("@/static/images/personal-avatar.png"), //个人默认头像
				companyAvatar: require("@/static/images/company-avatar.png"), //企业默认头像
				name: '',// 公司姓名
				// 更多操作
				moreOpertionSign: [{
						value: 0,
						text: "查看合同",
					},
					{
						value: 1,
						text: "撤回合同",
					},
					{
						value: 3,
						text: "查看更多",
					}
				],
				moreOpertionPre: [{
						value: 0,
						text: "查看合同",
					},
					{
						value: 1,
						text: "删除合同",
					},
					{
						value: 2,
						text: "查看更多",
					}
				],
				moreOpertionBack: [{
						value: "0",
						text: "查看合同",
					},
					{
						value: "1",
						text: "移除任务",
					},
					{
						value: "2",
						text: "删除合同",
					},
					{
						value: "3",
						text: "查看更多",
					}
				],
				moreOpertionPass: [{
						value: "0",
						text: "查看合同",
					},
					{
						value: "1",
						text: "抄送合同",
					},
					{
						value: "2",
						text: "解约合同",
					},
					{
						value: "3",
						text: "查看更多",
					},
				],
				moreOpertionTime: [{
						value: "0",
						text: "移除任务",
					},
					{
						value: "1",
						text: "抄送合同",
					},
					{
						value: "2",
						text: "查看更多",
					},
				],
				isCompany: '', //true企业 false个人
				valueDrop: 0, //dropDown的value
				listContractSignBack: [], //已终止
				listContractSignMine: [], //待我处理
				listContractSignOur: [], //待我方
				listContractSignOther: [], //待他方处理 
				listContractSignAllSuccess: [], //全通过
				listContractArchiveslistExpiredContract: [], //临期
				tabIndex: 0,
				labelList: [{
					title: '待我处理'
				}, {
					title: '待他方处理'
				}, {
					title: '签署全通过'
				}, {
					title: '签署已终止',
				}, {
					title: '临期合同'
				}],
				labelListCom: [{
					title: '待我处理'
				}, {
					title: '待我方处理'
				}, {
					title: '待他方处理'
				}, {
					title: '签署全通过'
				}, {
					title: '签署已终止',
				}, {
					title: '临期合同'
				}],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					indexTask: 0,
				},
			};
		},
  onLoad() {
    if (this.$store.getters.staffInfo.companyId == 0) {
      this.getInfo();
    } else {
      this.toRemindPupop(0);
    }
    uni.$on('tabIndex', data => {
      this.tabIndex = data
    })
    this.getDicts()
  },
		onReady(){
			// 获取swiper滚动区域高度
			uni.getSystemInfo({
			    success: (res) => {
			       	// let topHeight = (this.$refs.top.$el.offsetHeight * (750/res.windowWidth));
			   		let winHeight = (res.windowHeight * (750/res.windowWidth));
			   		this.boxHeight = winHeight  + 'rpx';
			   	}
			   });
		},
		onShow() {
            this.getStaffCertificationInfo();
			this.initData(true);
			this.getCurrentNameAndOtherInfoByStore();
			// this.companyWith = document.getElementsByClassName("com_name")[0].clientWidth
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.initData(true);
				this.getCurrentNameAndOtherInfoByStore();
				this.$modal.msgSuccess("刷新成功");
				uni.stopPullDownRefresh();
			}, 1000)
		},
		// onPageScroll(res) {
		// 	uni.$emit('onPageScroll', res.scrollTop);
		// },
		methods: {
			/** 签署延期 */
			outDateSetting(item){
				if(item.isStarter == 0){
					this.$modal.msgError('请联系发起方进行设置')
					return;
				}
				this.openContract(item)
			},
			/**加载数据字典*/
			getDicts() {
			  this.dicts.contract_sign_flow_status = getDictsByNameForUni("contract_sign_flow_status");
			},
			/** 设置合同终止时间 */
			settingEndTime(item){
				if(item.isStarter == 0){
					this.$modal.msgError('请联系合同发起方设置')
					return;
				}
				this.openContract(item)
			},
			/** 资料完善弹窗，个人支付密码弹窗 类型：0企业，1个人 */
      toRemindPupop(type) {
        // 个人
        if (type == 1) {
          if (!uni.getStorageSync("noSetPasswordForPserson") && this.$store.getters.staffInfo.isCertify == 1 && (!this.$store.getters.staffInfo.password || !this.$store.getters.staffInfo.payPassword)) {
            this.$nextTick(() => {
              //改为0 是因为页面内弹窗做了判断是个人还是企业
              this.$refs.remindPupop.openDialog(0);
            })
            uni.setStorageSync("noSetPasswordForPserson", "1")
          }
        }
        // 企业 实名认证通过弹窗
        if (type == 0) {
          if (!uni.getStorageSync("noSetPasswordForcCompany"+this.$store.getters.companyInfo.id) && this.$store.getters.staffInfo.isCertify == 1) {
            this.$nextTick(() => {
              this.$refs.remindPupop.openDialog(type);
            })
            uni.setStorageSync("noSetPasswordForcCompany"+this.$store.getters.companyInfo.id, "1")
          }
        }
      },
			/** 查询企业信息信息 */
      getInfo() {
        this.$modal.loading();
        // 检查是否有法人变更记录 待法人处理任务
        getLegalChangeRecordAuthAdmin().then(response => {
          uni.hideLoading()
          let data = response.data;
          // 存在法人操作任务 并且法人和管理员不是同一个人
          if (!!data && data.authAdminType == -1 && !data.isLegalAndAdmin) {
            this.$refs.legalCertify.openDialog(data);
          } else {
            // 个人弹窗
            this.toRemindPupop(1);
          }
        });
      },
			/** 底部加载更多 */
			onreachBottom(dataList){
				if (this.loadStatus != 'noMore' && this.total > dataList.length) {
					this.loadStatus = 'loading';
					// 延迟500毫秒显示loading效果
          this.queryParams.pageNum++;
          this.initData(false)
				} else {
					// 停止加载
					this.loadStatus = 'noMore'
				}
			},
			/** 重新发起 */
			againStart(item) {
				if (this.$store.getters.staffInfo.id !== item.systemStaffId) {
					this.$modal.msgError("经办人可重新发起！");
					return false;
				} else {
					let that = this
					uni.showModal({
						title: '系统提示',
						confirmColor: '#00a660',
						content: '重新生成新合同, 是否继续',
						success: function(res) {
							if (res.confirm) {
								againNewContract(item.contractId).then((response) => {
									that.$modal.msgSuccess("重新生成合同成功！");
									// 前往新窗口
									that.$tab.navigateTo(`/pages/sign/upSign?id=${response.data}`)
								}).catch(() => {});
							} else if (res.cancel) {
								that.$modal.msgError("已取消")
							}
						},
					})
				}
			},
			/** 催一下 */
			hurry(item) {
				contractHurry(item).then(response => {
					this.$modal.msgSuccess("您已成功通知本合同待签署人员，催其速签文件。")
				})
			},
			/** 签署全通过 */
			operAllPassDropdown(e,row) {
				if (e == 0) {
					// 查看合同 
					this.openContract(row)
				} else if (e == 1) {
					// 抄送合同 
					this.copyContract(row)
				}else if(e == 2){
					// 解约合同
					if (row.contractFlowJson == '解约文件') {
						this.$modal.msgError("解约文件不能再次解约！");
						return false;
					}
					// 解约合同页面
					this.$tab.navigateTo(`/pages/sign/rescindContract?id=${row.contractId}`)
				}else{
					// 查看更多
					uni.navigateTo({
						url:'/pages/common/contractManage/contractSign/listAllSuccess'
					})
				}
			},
			/** 合同已终止 更多操作 */
			operBackPassDropdown(e,row,index) {
				if (e == 0) {
					// 查看合同
					this.openContract(row)
				} else if (e == 1) {
					//清除任务
					this.deleteIndexTaskMethod(row);
				} else if (e == 2) {
					//  只有 草稿合同可以删除
					this.deleteContract(row);
				}else{
					// 查看更多
					uni.navigateTo({
						url:'/pages/common/contractManage/contractSign/listBack'
					})
				}
			},
			/** 临期合同 更多操作 */
			operExpiredDropdown(e,item) {
				if (e == 0) {
					this.deleteIndexTaskMethod(row);
				}else if(e == 1){
					uni.$emit('contractData',row)
					// 抄送合同
					this.copyContract(row)
				}else{
					uni.navigateTo({
						url:'/pages/common/contractManage/contractArchives/listExpired'
					})
				}
			},
			/** 待我处理 更多操作 */
			operMeDropdown(e,row, index) {
				console.log(e,'000')
				if (e == 0) {
					// 查看合同 
					this.openContract(row)
				} else if (e == 1) {
					// 只有待签署 状态才有撤回
					if (row.status == 1) {
						// 有撤回 无删除
						this.invalidContractId = row.contractId
						this.invalidIsStarter = true
						this.$refs.refusePopup.open()
					}else{
						//  只有 草稿合同可以删除
						if (row.signStatus === 0) {
							this.deleteContract(row)
						} else {
						   this.$modal.msgError("非拟稿合同不能删除");
						}        
					}
				} else {
					
					if(row.status==this.$enums.contractStatus.CONTENT_FILL || row.status==this.$enums.contractStatus.CONTROL_SET || row.status==this.$enums.contractStatus.ONE){
						uni.navigateTo({
							url:'/pages/common/contractManage/contract/contract'
						})
					}else{
						uni.navigateTo({
							url:'/pages/common/contractManage/contractSign/listMe'
						})
					}
				}
			},
			// 抄送合同
			copyContract(row){
				let data = {status:row.status,updateTime:row.updateTime,contractId:row.contractId,contractNumber:row.contractNumber,contractName:row.contractName}
				uni.navigateTo({
					url:'/pages/sign/addCopy?data='+JSON.stringify(data)
				})
			},
			// 清除任务方法
			deleteIndexTaskMethod(row) {
				let that = this
				uni.showModal({
					title: '系统提示',
					confirmColor: '#00a660',
					content: '移除首页待办任务, 是否继续？',
					success: function(res) {
						if (res.confirm) {
							deleteIndexTask(row.id).then((response) => {
								that.$modal.msgSuccess("清除任务成功！");
								that.initListContractSignBack(true);
							}).catch(() => {});
						} 
					},
				})
			},
			// 删除合同
			deleteContract(row, index) {
				let that = this
				uni.showModal({
					title: '系统提示',
					content: '确认删除该合同？',
					confirmColor: '#00a660',
					success: function(res) {
						if (res.confirm) {
							delContract(row.contractId);
							that.$nextTick(() => {
								that.initListContractSignMine(true);
								that.initListContractSignBack(true);
								that.$modal.msgSuccess("删除成功");
							})
						} else {}
					}
				})
			},
			/** 接受子组件传过来的值点击切换导航 */
			tabtap(index) {
        this.tabIndex = index;
        this.queryParams.pageNum = 1
			},
			handleSwiperChange(e){
				// this.tabIndex = e.detail.current;
        // 重置所有列表数据  此处重置是为了切换其他标签页 前一个标签页长列表数据很多并且不为空 切换标签页重新渲染卡顿问题
        this.clearAllListData();
        this.initData(true);
			},
      // 清空所有list数据
      clearAllListData() {
        this.listContractSignMine = [];
        this.listContractSignOur = [];
        this.listContractSignOther = [];
        this.listContractSignAllSuccess = [];
        this.listContractSignBack = [];
        this.listContractArchiveslistExpiredContract = [];
      },
			/** 滑动切换导航 */
			swiperChange(e) {
				this.tabIndex = e.detail.current
			},
			toggle() {
				this.$refs.popup.open()
			},
			initData(reload) {
				// 个人 点击tab事件
				if(this.$store.getters.staffInfo.companyId == 0){
					if(this.tabIndex == 0){
						this.initListContractSignMine(reload); // 待我处理
					}else if(this.tabIndex == 1){
						this.initListContractSignOther(reload);
					}else if(this.tabIndex == 2){
						this.initListContractSignAllSuccess(reload);
					}else if(this.tabIndex == 3){
						this.initListContractSignBack(reload);
					}else{
						this.initListContractArchiveslistExpiredContract(reload) //临期合同
					}

				}else{
					if(this.tabIndex == 0){
						this.initListContractSignMine(reload); // 待我处理 
					}else if(this.tabIndex == 1){
						this.initListContractSignOur(reload);
					}else if(this.tabIndex == 2){
						this.initListContractSignOther(reload);
					}else if(this.tabIndex == 3){
						this.initListContractSignAllSuccess(reload);
					}else if(this.tabIndex == 4){
						this.initListContractSignBack(reload);
					}else{
						this.initListContractArchiveslistExpiredContract(reload) //临期合同
					}
				}
			},
			// 切换身份 
			changeCompany(emit) {
				changeUser(emit.id).then(() => {
					updateSession().then((response) => {
						this.$store.dispatch('GetInfo').then((res) => {
							this.getCurrentNameAndOtherInfoByStore();
							// setTimeout(()=>{
							this.tabIndex = 0
							this.initListContractSignMine(true);
							// },1000) 
						});
					});
				});
			},
			getCurrentNameAndOtherInfoByStore() {
				this.companyId = this.$store.getters.staffInfo.companyId
				if (this.companyId == 0) {
					this.name = this.$store.getters.staffInfo.name
					this.isCertify = this.$store.getters.staffInfo.isCertify
					this.personAvatar = (this.$store.getters.staffInfo.avatar == "" || this.$store.getters.staffInfo
						.avatar == null) ? this.personAvatar : this.host + this.$store.getters.staffInfo.avatar;
						this.$nextTick(()=>{
							this.companyWith = document.getElementsByClassName("com_name")[0].clientWidth
						})
					// 查询个人可用签署数量
					getRemainingNum({
						staffId: this.$store.getters.staffInfo.id
					}).then((response) => {
						this.remainingNum = response.data;
					});
				} else {
					this.isCertify = this.$store.getters.companyInfo.isCertify
					this.name = this.$store.getters.companyInfo.name
					this.companyAvatar = (this.$store.getters.companyInfo.avatar == "" || this.$store.getters.companyInfo
						.avatar == null) ? this.companyAvatar : this.host + this.$store.getters.companyInfo.avatar;
						this.$nextTick(()=>{
							this.companyWith = document.getElementsByClassName("com_name")[0].clientWidth
						})
					// 查询企业可用签署量
					getRemainingNum({
						companyId: this.$store.getters.companyInfo.id
					}).then((response) => {
						this.remainingNum = response.data;
					});
				}
			},
			/** 待他方处理跳转 */
			openOtherContract(row) {
				this.$tab.navigateTo(`/pages/sign/detail?id=${row.contractId}&flowId=${row.id}`)
			},
			openContract(row) {
				if (row.signStatus === 1) {
					// 待签署
					if (row.status == 1) {
						this.$tab.navigateTo(`/pages/sign/signedByme?id=${row.contractId}&flowId=${row.id}`)
					} else {
						this.$tab.navigateTo(`/pages/sign/detail?id=${row.contractId}&flowId=${row.id}`)
					}
				}
				if (row.signStatus === 0) {
					switch (row.status) {
						case 0:
							this.$tab.reLaunch(`/pages/sign/sign?id=${row.contractId}&flowId=${row.id}`)
							break;
						case 1:
							this.$tab.navigateTo(`/pages/sign/signedByme?id=${row.contractId}&flowId=${row.id}`)
							break;
						case 2:
							this.$tab.navigateTo(`/pages/sign/docfill?id=${row.contractId}&flowId=${row.id}`)
							break;
						case 3:
							this.$tab.navigateTo(`/pages/sign/upSign?id=${row.contractId}&flowId=${row.id}`)
							break;
						case 4:
							this.$tab.navigateTo(`/pages/sign/signedByme?id=${row.contractId}&flowId=${row.id}`)
							break;
						case 6:
							this.$tab.navigateTo(`/pages/sign/upSign?id=${row.contractId}&flowId=${row.id}`)
							break;	
						case 13:
							this.$tab.navigateTo(`/pages/sign/signedByme?id=${row.contractId}&flowId=${row.id}`)
							break;		
						default:
							this.$tab.navigateTo(`/pages/sign/detail?id=${row.contractId}&flowId=${row.id}`)
							break;
					}
				}
			},
			// 计算日期差
			getTimeDiff(date) {
				return getDateDiff(parseTime(new Date(), "{y}-{m}-{d}"), transformTime(date)) * 24;
			},
			/**
			 * 查询列表 待我处理  查询合同列表
			 * @param reload true 重新加载数据； false 加载更多 
			 */
			initListContractSignMine(reload) {
				if (reload) {
					this.queryParams.pageNum = 1;
					this.loadStatus = 'more'
                    this.$modal.loading();
				}
				listMainPageMe(this.queryParams).then(response => {
					if (reload) {
						uni.hideLoading()
					}
					this.total = response.total;
					if (response.total > 0) {
						const dataRows = response.rows;
						this.listContractSignMine = reload ? dataRows : this.listContractSignMine.concat(dataRows);
						this.listContractSignMine.forEach((flow) => {
						    flow.contractTipEndTime = getHourNowDiff(flow.signExpiryDate);
						});      
					} else {
						this.listContractSignMine = [];
					}
					// 判断数据是否加载完全
					if (response.total <= this.listContractSignMine.length) {
						this.loadStatus = 'noMore'
					}
				}).catch(() => {
					if (reload) {
						uni.hideLoading()
					}
				});
			},
			// 待我方处理
			initListContractSignOur(reload) {
				if (reload) {
					this.queryParams.pageNum = 1;
					this.loadStatus = 'more'
                    this.$modal.loading();
				}
				listContractSignOur().then(response => {
					if (reload) {
						uni.hideLoading()
					}
					this.total = response.total;
					if (response.total > 0) {
						const dataRows = response.rows;
						this.listContractSignOur = reload ? dataRows : this.listContractSignOur.concat(dataRows);
						this.listContractSignOur.forEach(flow => {
							// 截止时间
							flow.contractTipEndTime = getHourNowDiff(flow.signExpiryDate);
						})
					} else {
						this.listContractSignOur = [];
					}
					// 判断数据是否加载完全
					if (response.total <= this.listContractSignOur.length) {
						this.loadStatus = 'noMore'
					}
				}).catch(() => {
					if (reload) {
						uni.hideLoading()
					}
				});
			},
			// 待他方处理
			initListContractSignOther(reload) {
				if (reload) {
					this.queryParams.pageNum = 1;
					this.loadStatus = 'more'
                this.$modal.loading();
				}
				listContractSignOther(this.queryParams).then(response => {
					if (reload) {
						uni.hideLoading()
					}
					this.total = response.total;
					if (response.total > 0) {
						const dataRows = response.rows;
						this.listContractSignOther = reload ? dataRows : this.listContractSignOther.concat(dataRows);
						this.listContractSignOther.forEach(flow => {
							// 截止时间 
							flow.contractTipEndTime = getHourNowDiff(flow.signExpiryDate);
						})
					} else {
						this.listContractSignOther = [];
					}
					// 判断数据是否加载完全
					if (response.total <= this.listContractSignOther.length) {
						this.loadStatus = 'noMore'
					}
				}).catch(() => {
					if (reload) {
						uni.hideLoading()
					}
				});
			},
			// 签署全通过
			initListContractSignAllSuccess(reload) {
				if (reload) {
					this.queryParams.pageNum = 1;
					this.loadStatus = 'more'
                    this.$modal.loading();
				}
				listContractSignAllSuccess(this.queryParams).then(response => {
					if (reload) {
							uni.hideLoading()
						}
						this.total = response.total;
						if (response.total > 0) {
							const dataRows = response.rows;
							this.listContractSignAllSuccess = reload ? dataRows : this.listContractSignAllSuccess.concat(dataRows);
							this.listContractSignAllSuccess.forEach(flow => {
								flow.contractTipEndTime = getDateDiff(parseTime(new Date(), "{y}-{m}-{d}"),
									transformTime(flow.contractEndTime));
							})
						} else {
							this.listContractSignAllSuccess = [];
						}
						// 判断数据是否加载完全
						if (response.total <= this.listContractSignAllSuccess.length) {
							this.loadStatus = 'noMore'
						}
					}).catch(() => {
						if (reload) {
							uni.hideLoading()
						}
					});
			},
			// 已临期合同
			initListContractArchiveslistExpiredContract(reload) {
				if (reload) {
					this.queryParams.pageNum = 1;
					this.loadStatus = 'more'
                    this.$modal.loading();
				}
				listContractArchiveslistExpiredContract(this.queryParams).then(response => {
					if (reload) {
							uni.hideLoading()
						}
						this.total = response.total;
						if (response.total > 0) {
							const dataRows = response.rows;
							this.listContractArchiveslistExpiredContract = reload ? dataRows : this.listContractArchiveslistExpiredContract.concat(dataRows);
							this.listContractArchiveslistExpiredContract.forEach(flow => {
								flow.reminderTime = flow.contractTipEndTime
								flow.contractTipEndTime = getDateDiff(parseTime(new Date(), "{y}-{m}-{d}"), transformTime(flow.contractEndTime));
							})
						} else {
							this.listContractArchiveslistExpiredContract = [];
						}
						// 判断数据是否加载完全
						if (response.total <= this.listContractArchiveslistExpiredContract.length) {
							this.loadStatus = 'noMore'
						}
					}).catch(() => {
						if (reload) {
							uni.hideLoading()
						}
					});
			},
			// 签署已终止
			initListContractSignBack(reload) {
				if (reload) {
					this.queryParams.pageNum = 1;
					this.loadStatus = 'more'
                    this.$modal.loading();
				}
				listContractSignBack(this.queryParams).then(response => {
					if (reload) {
							uni.hideLoading()
						}
						this.total = response.total;
						if (response.total > 0) {
							const dataRows = response.rows;
							this.listContractSignBack = reload ? dataRows : this.listContractSignBack.concat(dataRows);
							this.listContractSignBack.forEach(flow => {
								flow.reminderTime = flow.contractTipEndTime //到期提醒时间
								flow.contractTipEndTime = getDateDiff(parseTime(new Date(), "{y}-{m}-{d}"),
									transformTime(flow.contractEndTime));
								flow.nowTime = parseTime(new Date(), "{y}-{m}-{d} {h}:{i}:{s}") //当前时间
							})
						} else {
							this.listContractSignBack = [];
						}
						// 判断数据是否加载完全
						if (response.total <= this.listContractSignBack.length) {
							this.loadStatus = 'noMore'
						}
					}).catch(() => {
						if (reload) {
							uni.hideLoading()
						}
					});
			},
      // =================================================================================================================
      // ==== 个人认证信息，检查是否需要强制弹窗 完善证件
      // =================================================================================================================
      /** 获取认证信息 */
      getStaffCertificationInfo() {
        // 个人是否认证
        if(this.$store.getters.staffInfo.isCertify == 0){
			setTimeout(()=>{
				this.$refs.personalAuth.open()
			},300)
   //        uni.showModal({
   //          title: '未实名认证',
			// confirmText:'立即认证',
   //          content: '1、为确保您通过励氪签平台签署的文件符合国家法律、法规要求以及励氪签为您申请制作的电子签名为您本人专有，您需要先进行个人实名认证；\n2、申请人需年满16周岁，仅支持持有：中国居民身份证、港澳台居民来往内地通行证、中国港澳台居民居住证、外国人居住证的个人进行实名认证；',
   //          cancelText: '退出',
   //          success: (res)=> { 
   //            if (res.confirm) {
   //              uni.reLaunch({url: "/pages/authentication/personal/personal"})
   //            } else if (res.cancel) {
   //              this.$store.dispatch('LogOut').then(() => {
   //                this.$tab.reLaunch('/pages/index')
   //              })
   //            }
   //          }
   //        });
        }
        getStaffCertification().then(response => {
          let saffCertInfo = response.data;
          // 弹窗完善证件
          if (!!saffCertInfo && saffCertInfo.credentialStatus == 0 && saffCertInfo.credentialForcePop == 1) {
            uni.showModal({
              title: '请完善证件',
              content: '根据国家法律法规规定，请您尽快完善身份证件信息，以免影响您正常使用。',
              showCancel: false,// 没有取消按钮的弹框
              confirmText:"立即完善",
              success: function (res) {
                uni.navigateTo({url: '/pages/mine/personal/personalCenter/perfectInfo'});
              }
            });
          }
        });
      },
      /** 完善证件成功 回调 */
      perfectInfoSuccess(){
       this.getStaffCertificationInfo();
      },
	  /** 头像信息 */
	  comapnyCenter() {
	    this.$tab.navigateTo('/pages/mine/work/companyInfo')
	  },
	  personCenter(){
		  this.$tab.navigateTo('/pages/mine/personal/personalCenter/userInfo')
	  }
		},
	};
</script>

<style lang="scss" scoped>
	::v-deep .uni-select__selector{
		position: absolute;
		top: 40rpx;
		right: -8rpx;
	}
	::v-deep .uni-date{
		flex: none!important;
	}
	.settingBtn{
		color: orange;
		font-size: 26rpx;
		width: 102rpx;
	}
	.scroll_view{
		overflow-y: scroll;
	}
	.jiantou{
		font-size: 26rpx;
		padding-left:10rpx;
		color: #fff;
		padding-top: 4rpx;
	}
	::v-deep uni-swiper .uni-swiper-wrapper {
	     overflow-y: auto!important;
	}

	 ::v-deep uni-swiper-item {
	     overflow-y: auto!important;
	}

	::v-deep .dropdown-item__content .list {
		right: 20rpx;
	}

	::v-deep .dropdown-item__content .list__option {
		padding: 20rpx 48rpx;
	}

	// tab固定
	.tabs {
		z-index: 10;
		position: fixed;
		top: 130rpx;
		width: 100%;
	}

	.tabplane_top {
		margin-top: 200rpx;
		// position: relative;
	}

	// 实名认证图标
	.certiyImg {
		width: 30rpx;
		height: 30rpx;
		margin:0 6rpx;
		color: $uni-color-primary;
	}

	.marSat {
		margin-left: 8rpx;
	}

	// 合同标题
	.contract_title {
		width: calc(100vw - 100rpx);
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1; //显示行数
		white-space: nowrap;
		color: #666666;
		font-size: 30rpx;
	}

	.contract_num {
		font-size: 26rpx;
		color: #666666;
	}

	.certiy {
		font-size: 25rpx;
	}

	.home {
		width: 100%;
		// position: relative;
	}

	// 任务处理标签页
	.tabspane {
		margin: 20rpx 0 0;
		padding: 20rpx 30rpx;
		background: #fff;
		// box-shadow: 0rpx 4rpx 64rpx 0rpx rgba(60, 60, 60, 0.09); 
		width: 100%;

		.xieyi {
			display: flex;
			justify-content: space-between;
			color: #4a4a4a;
			padding: 4rpx 0;
			margin: 0;

			.outIcon {
				color: #999999;
				// position: relative;
			}
		}

		.sign {
			border-top: 1rpx solid #e7e7e7;
			font-size: 24rpx;
			color: #ff8a4a;
			padding-top: 10rpx;
			margin-top: 8rpx;
			display: flex;
			justify-content: space-between;
		}

		.content {
			margin-top: 10rpx;
			font-size: 26rpx;
			color: #8f8f8f;

			view {
				padding: 4rpx 0;
			}

			.contr_compeo {
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1; //显示行数
				white-space: nowrap;
			}

			span {
				color: rgb(255, 87, 34);
				float: right;
			}
		}
	}

	// 账号信息显示
	.header {
		background-color: $uni-color-primary;
		padding: 20rpx 30rpx 20rpx 30rpx;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 4;
		.account_info {
			display: flex;
			align-items: center;

			.account {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
			}

			.com_name {
				// width: 73%;
				// 文本溢出用省略号代替
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				margin: 0;
				font-size: 30rpx;
				display: inline-block;
			}

			.over_p {
				font-size: 28rpx;
				color: #fff;
				width: calc(100vw - 175rpx);
				margin: 0 0 0 10rpx;
				display: flex;
				align-items: center;
			}

			.sign_item {
				font-size: 26rpx;
				margin: 8rpx 0 0 10rpx;
				color: #fff;
			}
		}
	}
</style>
